package com.cl.code.common.utils;

import com.cl.code.common.model.number.NumberGenerator;
import com.cl.code.common.model.number.SerialNumberGenerator;

/**
 * @author chengliang
 * @since 1.0.0
 */
public class NumberGeneratorUtils {
    private static final NumberGenerator NUMBER_GENERATOR;

    static {
        NUMBER_GENERATOR = SerialNumberGenerator.builder()
                .connector('-')
                .useDigits(true)
                .useLower(true)
                .build();
    }

    public static String generate() {
        return NUMBER_GENERATOR.generate();
    }

    public static String generate(int length) {
        if (length <= 0) {
            throw new IllegalArgumentException("Length must be greater than 0");
        }
        return NUMBER_GENERATOR.generate("", length);
    }

    public static String generate(String prefix) {
        if (prefix == null || prefix.isEmpty()) {
            throw new IllegalArgumentException("Prefix cannot be null or empty");
        }
        return NUMBER_GENERATOR.generate(prefix);
    }

    public static String generate(String prefix, int length) {
        if (prefix == null || prefix.isEmpty()) {
            throw new IllegalArgumentException("Prefix cannot be null or empty");
        }
        if (length <= 0) {
            throw new IllegalArgumentException("Length must be greater than 0");
        }
        return NUMBER_GENERATOR.generate(prefix, length);
    }

    public static String generate(String prefix, Character connector, int length) {
        if (prefix == null || prefix.isEmpty()) {
            throw new IllegalArgumentException("Prefix cannot be null or empty");
        }
        if (connector == null) {
            throw new IllegalArgumentException("Connector cannot be null");
        }
        if (length <= 0) {
            throw new IllegalArgumentException("Length must be greater than 0");
        }
        return NUMBER_GENERATOR.generate(prefix, connector, length);
    }

}
